#!/bin/bash

if [ $# == 0 ]; then
	echo "Usage:"
	echo "./sigma_map <z lens> <z source> <nfw mass> <nfw c> <gridhi>"
        echo
	exit 1
fi

zl=$1
zs=$2
mass=$3
c=$4
gridhi=$5

# Clean environment
rm *.dat
rm *.gl
rm *.lens

ksmod="ksmod"

kappas=$($ksmod $zl $zs $mass $c 0.25 0.75 | cut -f1 | cut -d' ' -f2)
tmp=$($ksmod $zl $zs $mass $c 0.25 0.75 | cut -f2 | cut -d' ' -f2)
xsL=$(echo "$tmp * 60.0" | bc -l)


eL=0.1
thetaL=-70

# NFW analytic model

echo "
set plotmode=2
set gridhi1=$gridhi
startup 1 1
nfw $kappas 0 0 $eL $thetaL 0 0 $xsL 0 0 
0 0 0 0 0 0 0 0 0 0
#makekapmap kappa_map.fits 3 kappa_map.range -$gridhi $gridhi 500 -$gridhi $gridhi 500

plotcrit cc.dat
plotgrid grid.dat

#setsource 1
#  sersic 1.0 0.0 0.0 0.0 0.0 0.03 0 0.5 macro
#  0 0 0 0 0 0 0 0

#SBmap2 -$gridhi $gridhi 500 -$gridhi $gridhi 500 1 arcs.fits 3

" > nfw.gl

gravlens nfw.gl > nfw.log

echo "
set plotmode=2
set gridhi1=$gridhi
set maxlev=6

set zlens=$zl
set zsrc=$zs

set omega=0.25
set lambda=0.75
set hval=0.75

sig2lens sigma.txt 1 sigma.range kappamap.lens
  
loadkapmap kappamap.lens 1 1
  
startup 1 1
   kapmap 1.0 0 0 0 0 0 0 0 0 1
   0 0 0 0 0 0 0 0 0 0
  
plotcrit cc_kapmap.dat
plotgrid grid_kapmap.dat
  
#setsource 1
#  sersic 1.0 0.0 0.0 0.0 0.0 0.03 0 0.5 macro
#  0 0 0 0 0 0 0 0
#SBmap2 -$gridhi $gridhi 512 -$gridhi $gridhi 512 1 ering_kapmap.fits 3
  
" > sigma.gl

gravlens sigma.gl > sigma.log

./plot.sh 30 compare.png

echo "kappas=$kappas"
echo "xsL=$xsL"
echo "gridhi=$gridhi"


